local skel = fk.CreateSkill {
  name = "rmt__deze",
}

skel:addEffect("viewas", {
  name = "rmt__deze",
  pattern = "slash,peach",
  prompt = function (self, player)
    if player and table.every(player:getCardIds("h"), function(id) return Fk:getCardById(id).color == Card.Red end) then
      return "#rmt__deze-red"
    end
    return "#rmt__deze"
  end,
  interaction = function (self, player)
    local names = player:getViewAsCardNames(skel.name, {"slash", "peach"})
    if #names > 0 then
      return UI.CardNameBox { choices = names }
    end
  end,
  card_filter = Util.FalseFunc,
  before_use = function (self, player, use)
    local room = player.room
    local skills = table.map(table.filter(player.player_skills, function (s)
      return s:isPlayerSkill(player) and s.visible
    end), Util.NameMapper)
    if #skills == 0 then return "" end
    local skill = room:askToChoice(player, {choices = skills, skill_name = skel.name, prompt = "#rmt__deze-delete"})
    local cards = player:getCardIds("h")
    player:showCards(cards)
    if table.every(cards, function(id) return Fk:getCardById(id).color == Card.Red end) then
      room:addTableMark(player, "rmt__deze-turn", skill)
    end
    room:handleAddLoseSkills(player, "-"..skill)
  end,
  view_as = function(self)
    local name = self.interaction.data
    if name == nil then return end
    local card = Fk:cloneCard(name == "slash" and "thunder__slash" or name)
    card.skillName = skel.name
    return card
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng() and table.find(player.player_skills, function (s)
      return s.visible and s:isPlayerSkill(player)
    end)
  end,
  enabled_at_response = function (self, player, response)
    return not response and not player:isKongcheng()
    and table.find(player.player_skills, function (s)
      return s.visible and s:isPlayerSkill(player)
    end)
  end,
})

skel:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("rmt__deze-turn") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, table.concat(player:getMark("rmt__deze-turn"), "|"))
  end,
})

Fk:loadTranslationTable{
  ["rmt__deze"] = "德泽",
  [":rmt__deze"] = "你可以展示手牌以将一个技能当雷【杀】或【桃】使用；若均为红色，本回合结束时你复原因此失去的技能。",
  ["#rmt__deze"] = "德泽：展示手牌并将一个技能当雷【杀】或【桃】使用",
  ["#rmt__deze-red"] = "德泽：展示手牌，将1个技能当雷【杀】或【桃】使用(回合结束时复原！)",
  ["#rmt__deze-delete"] = "德泽：请移去一个技能",

  ["$rmt__deze1"] = "天作云雷，沛然德泽！",
  ["$rmt__deze2"] = "三光全、寒暑平，受天祜，享鬼神。",
}

return skel
